package core;

import org.junit.Test;

/**
 * 冒泡排序
 * Created by admin on 2017/2/27.
 */

public class BubbleSort {
    public static void main(String[] args) {
        int[] arr={6,3,5,8,2,4,9,7,1};
        System.out.println("排序前的数组为：");
        for(int num:arr){
            System.out.print(num+" ");
        }
        for(int i=0;i<arr.length-1;i++){//外层循环控制排序趟数
            for(int j=0;j<arr.length-1-i;j++){//内层循环控制每一趟排序多少次
                if(arr[j]>arr[j+1]){
                    int temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        System.out.println();
        System.out.println("排序后的数组为：");
        for(int num:arr){
            System.out.print(num+" ");
        }
    }

    @Test
    public void testReverse(){
        String str = "hello";

        for (int i = str.length() - 1; i >= 0; i--) {

            char c = str.charAt(i);

            System.out.print(c);
        }
        System.out.println();
        String s = "abcdefg";
        s = reverse(s);
        System.out.println("反转后的字符串:"+s);
    }

    public static String reverse(String str){
        return new StringBuilder(str).reverse().toString();
    }
}
